<template>
  <vxe-modal
    title="证书查看"
    v-model="dialogVisible"
    v-if="dialogVisible"
    :loading="loading"
    width="75%" showFooter esc-closable show-zoom resize>

    <!-- 顶部搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="年度" prop="nd">
        <el-input size="mini"
                  v-model="queryParams.nd"
                  placeholder="请输入年度"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="软件名称" prop="rjName">
        <el-input size="mini"
                  v-model="queryParams.rjName"
                  placeholder="请输入软件名称"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证书号" prop="zsh">
        <el-input size="mini"
                  v-model="queryParams.zsh"
                  placeholder="请输入证书号"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登记号" prop="djh">
        <el-input size="mini"
                  v-model="queryParams.djh"
                  placeholder="请输入登记号"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table height="40vh" @row-click="clickRow" ref="table" highlight-current-row
              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
              v-loading="loading" :data="rjsqdjList" @selection-change="handleSelectionChange">
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>
      <el-table-column show-overflow-tooltip type="number" label="年度" align="center" prop="nd" width="60"/>
      <el-table-column show-overflow-tooltip label="软件名称" align="center" prop="rjName">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleRjSqDjXqClick(scope.row)"
          >
            <el-link type="primary"><span style="font-size: 12px">{{ scope.row.rjName }}</span></el-link>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="证书号" align="center" prop="zsh"/>
      <el-table-column show-overflow-tooltip label="登记号" align="center" prop="djh"/>
      <el-table-column show-overflow-tooltip label="版本号" align="center" prop="bbh" width="80"/>
      <el-table-column show-overflow-tooltip label="著作权人" align="center" prop="zzqR"/>
      <el-table-column show-overflow-tooltip label="首次发表日期" align="center" prop="scFbRq" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.scFbRq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="登记日期" align="center" prop="djRq" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.djRq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="完成单位" align="center" prop="wcDw">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xmgl_lxwj_pzdw" :value="scope.row.wcDw"/>
        </template>
      </el-table-column>
      <!--      <el-table-column label="所属领域" align="center" prop="ssLy">-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.kylx_ssly" :value="scope.row.ssLy"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="证书图片" align="center" prop="zsTp" width="100">-->
      <!--        <template slot-scope="scope">-->
      <!--          <image-preview :src="scope.row.zsTp" :width="50" :height="50"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column show-overflow-tooltip label="软著申请关联" align="center" prop="rzSqGl">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleButtonClick(scope.row)"
          >
            <el-link type="primary"><span style="font-size: 12px">{{ scope.row.rzSqGl }}</span></el-link>
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <div slot="footer" class="dialog-footer dialog-footer-center">
      <el-button @click="dialogVisible=false">关闭</el-button>
    </div>

    <!-- 软件授权登记详情 -->
    <RjSqDjXq ref="rjSqDjXq"/>

    <!-- 软著详情 -->
    <RzXq ref="rzXq"/>
  </vxe-modal>
</template>

<script>
import {listRjsqdj} from "@/api/zscq/rzgl/rjsqdj";
import RjSqDjXq from "@/views/zscq/rjsqdj/components/RjSqDjXq.vue";
import RzXq from "@/views/zscq/rzgl/rzsq/components/RzXq.vue";

export default {
  name: "RjSqDjList",
  components: {RzXq, RjSqDjXq},
 //根据rzsqId查询符合条件的软件授权登记列表
  dicts: ['xmgl_lxwj_pzdw', 'kylx_ssly'],
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      dialogVisible: false,
      loading: false,
      rzsqId: null, //传过来的软著申请ID
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nd: null,
        rjName: null,
        zsh: null,
        djh: null,
        wcDw: null,
        rzsqId: this.rzsqId,
        idWhere: null,
        userId: null,
        deptId: null,
        rzSqGl: null
      },
      selectedRow: null, // 保存当前选中的行
      // 总条数
      total: 0,
      // 软件授权登记表格数据
      rjsqdjList: [],

    }
  },
  created() {

  },
  methods: {
    handleOpen(row) {
      this.loading = true;
      this.rzsqId = row.rzsqId
      this.dialogVisible = true
      this.getList()
      setTimeout(() => {
        this.loading = false
      }, 1000)
    },
    /** 查询软件授权登记列表 */
    getList() {
      this.loading = true;
      this.queryParams.rzsqId = this.rzsqId
      listRjsqdj(this.queryParams).then(response => {
        this.rjsqdjList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 自定义序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if ((pageNum !== -1 && pageNum !== 0)) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return (index + 1)
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //点击行 获取行
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      const table = this.$refs.table;
      const selectedRows = table.selection;

      // 否则取消之前选中的行，并选中当前点击的行
      selectedRows.forEach(selectedRow => {
        table.toggleRowSelection(selectedRow);
      });
      table.toggleRowSelection(row);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      let ids = selection.map(item => item.rjsqdjId)
      if (ids.length === 1) {
        this.ids = ids[0]
      } else {
        this.ids = ids
      }
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    //打开软件授权登记详情
    handleRjSqDjXqClick(row) {
      this.$refs.rjSqDjXq.handleOpen(row);
    },
    //打开软著申请详情
    handleButtonClick(row) {
      this.$refs.rzXq.handleOpen(row);
    },

  },
}
</script>

<style scoped>

</style>
